import jwt from "jsonwebtoken";

export const checkAuth = (req,res,next)=>{
    
    const auth = req.headers['authorization']
    if(!auth){
        res.status(401).json({
            code:1,
            msg:"暂无权限"
        })
    }else{
        const token = auth.split(' ')[1];
        const obj = jwt.verify(token,"shn") 
        req.username = obj.username;

        next();
    }
}